package com.wk.code.wkserver.config.application;

import com.wk.code.wkserver.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringBootVersion;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author: wangqiang
 * @create: 2021-08-25 10:03
 */
@Component
@Slf4j
public class WkApplication implements CommandLineRunner {

    @Resource
    private Environment env;

    @Override
    public void run(String... args) {
        log.debug("Let's inspect the beans provided by Spring Boot:");
        String version = SpringBootVersion.getVersion();
        log.info(String.format("\n----------------------------------------------------------\n\t" +
                        "Application '%s' is running at '%s'! \n\t" +
                        "The project Access URL: http://localhost:%s\n\t" +
                        "The following profiles are active: %s\n" +
                        "\tThe project springboot version: %s\n" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                DateUtils.localDate2Time(LocalDateTime.now()),
                env.getProperty("server.port"),
                env.getProperty("spring.profiles.active"), version));
    }
}
